package com.supinfo.suptracking.servlet;

import com.supinfo.suptracking.entity.Zone;
import com.supinfo.suptracking.service.ZoneService;
import java.io.IOException;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Fabien, Jérémy, Ludovic, Brice
 */

@WebServlet(name = "ZonesServlet", urlPatterns = {"/auth/zones"})
public class ZonesServlet extends HttpServlet {
    
    @EJB
    private ZoneService zoneService;
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {		
        List<Zone> zones = zoneService.processGetAllZone();
        if(zones.isEmpty()){
            response.sendRedirect(getServletContext().getContextPath()+ "/jsp/auth/zones.jsp");
        }
        else{
            request.setAttribute("zones", zones);
            request.getSession().setAttribute("zones", zones);
            response.sendRedirect(getServletContext().getContextPath()+ "/jsp/auth/zones.jsp");
        }
    }
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doGet(req, resp);  
    }
}
